package com.share.module.business.stockprofit.web;

import com.share.module.business.stockprofit.entity.StockProfit;
import com.share.module.business.stockprofit.service.StockProfitService;
import com.share.module.business.stockprofit.vo.*;
import com.stock.common.lang.StringUtils;
import com.stock.common.response.ApiResult;
import com.stock.mybatisplus.utils.PageUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 股票净利润 前端控制器
 * </p>
 *
 * @author lijy
 * @since 2025-11-07
 */
@Tag(name = "股票净利润管理", description = "股票净利润信息的增删改查接口")
@RestController
@RequestMapping("/stockprofit")
public class StockProfitController {

    @Resource
    private StockProfitService stockProfitService;

    @Operation(summary = "分页查询股票净利润", description = "根据条件分页查询股票净利润列表")
    @GetMapping("/page")
    public ApiResult<PageUtils<StockProfitPageVO>> findPage(
            @Parameter(description = "分页查询条件") StockProfitPageQueryVO vo) {
        PageUtils<StockProfitPageVO> pageUtils = stockProfitService.page(vo);
        return ApiResult.success(pageUtils);
    }

    @Operation(summary = "保存或更新股票净利润", description = "新增或更新股票净利润信息,有id则更新,无id则新增")
    @PostMapping
    public ApiResult<Boolean> save(
            @Valid @RequestBody @Parameter(description = "股票净利润保存对象") StockProfitSaveVO vo) {
        StockProfit stockProfit = new StockProfit();
        stockProfit.setId(vo.getId());
        stockProfit.setStockCode(vo.getStockCode());
        stockProfit.setFiscalYear(vo.getFiscalYear());
        stockProfit.setQ1NetProfit(vo.getQ1NetProfit());
        stockProfit.setQ1NoneNetProfit(vo.getQ1NoneNetProfit());
        stockProfit.setQ1Eps(vo.getQ1Eps());
        stockProfit.setQ2NetProfit(vo.getQ2NetProfit());
        stockProfit.setQ2NoneNetProfit(vo.getQ2NoneNetProfit());
        stockProfit.setQ2Eps(vo.getQ2Eps());
        stockProfit.setQ3NetProfit(vo.getQ3NetProfit());
        stockProfit.setQ3NoneNetProfit(vo.getQ3NoneNetProfit());
        stockProfit.setQ3Eps(vo.getQ3Eps());
        stockProfit.setQ4NetProfit(vo.getQ4NetProfit());
        stockProfit.setQ4NoneNetProfit(vo.getQ4NoneNetProfit());
        stockProfit.setQ4Eps(vo.getQ4Eps());
        if (StringUtils.isNotEmpty(stockProfit.getId())) {
            stockProfitService.updateById(stockProfit);
        } else {
            stockProfit.setId(null);
            stockProfitService.save(stockProfit);
        }
        return ApiResult.success();
    }

    @Operation(summary = "批量删除股票净利润", description = "根据ID列表批量删除股票净利润")
    @PostMapping("/del/batch")
    public ApiResult<Boolean> batchDel(
            @RequestBody @Parameter(description = "股票净利润ID列表") List<String> ids) {
        return ApiResult.success(stockProfitService.removeByIds(ids));
    }

    @Operation(summary = "删除股票净利润", description = "根据ID删除单个股票净利润")
    @DeleteMapping("/{id}")
    public ApiResult<Boolean> delete(
            @PathVariable @Parameter(description = "股票净利润ID") String id) {
        return ApiResult.success(stockProfitService.removeById(id));
    }

    @Operation(summary = "查询股票净利润详情", description = "根据ID查询股票净利润详细信息")
    @GetMapping("/{id}")
    public ApiResult<StockProfitViewVO> findOne(
            @PathVariable @Parameter(description = "股票净利润ID") String id) {
        StockProfit stockProfit = stockProfitService.getById(id);
        if (stockProfit == null) {
            return ApiResult.error("数据不存在");
        }
        StockProfitViewVO viewVO = new StockProfitViewVO();
        viewVO.setId(stockProfit.getId());
        viewVO.setStockCode(stockProfit.getStockCode());
        viewVO.setFiscalYear(stockProfit.getFiscalYear());
        viewVO.setQ1NetProfit(stockProfit.getQ1NetProfit());
        viewVO.setQ1NoneNetProfit(stockProfit.getQ1NoneNetProfit());
        viewVO.setQ1Eps(stockProfit.getQ1Eps());
        viewVO.setQ2NetProfit(stockProfit.getQ2NetProfit());
        viewVO.setQ2NoneNetProfit(stockProfit.getQ2NoneNetProfit());
        viewVO.setQ2Eps(stockProfit.getQ2Eps());
        viewVO.setQ3NetProfit(stockProfit.getQ3NetProfit());
        viewVO.setQ3NoneNetProfit(stockProfit.getQ3NoneNetProfit());
        viewVO.setQ3Eps(stockProfit.getQ3Eps());
        viewVO.setQ4NetProfit(stockProfit.getQ4NetProfit());
        viewVO.setQ4NoneNetProfit(stockProfit.getQ4NoneNetProfit());
        viewVO.setQ4Eps(stockProfit.getQ4Eps());
        return ApiResult.success(viewVO);
    }
}
